public class Demo9 {
    public static int count = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                count++;
            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                count++;
            }
        });

//        t.start();
//        t2.start();
//        t.join();//如果没有join,三个线程同时执行,则最后输出并不是t t2 计算完的效果(并发执行)
//        t2.join();

        //串行执行
        t.start();
        t.join();
        t2.start();
        t2.join();

        System.out.println("count = "+count);//预期是10000,但是实际值小于预测值,且每次不一样--->BUG-->少加
    }
}
